<template>
	<!-- 最外层的容器 -->
	<view class="my-settle-container">
		<!-- 全选区域 -->
		<label class="radio">
			<radio color="#C00000" :checked="isFullCheck" @click="fullCheckHandle" /><text>全选</text>
		</label>

		<!-- 合计区域 -->
		<view class="amount-box">
			<text style="color: #9f9f9f; font-size: 13px;"> 已选{{checkedCount}}件,</text>合计:<text
				class="amount">{{checkedGoodsAmount}} 元</text>
		</view>

		<!-- 结算按钮 -->
		<view @click="settlement" class="btn-settle">结算</view>
	</view>
</template>

<script>
	import {
		mapGetters,
		mapMutations,
		mapState
	} from 'vuex'
	export default {
		computed: {
			...mapGetters('m_cart', ['checkedCount', 'total', 'checkedGoodsAmount']),
			// addstr 是详细的收货地址
			...mapGetters('m_user', ['addstr', 'getUserInfo']),
			// token 是用户登录成功之后的 token 字符串
			//引入m_user对象
			...mapState('m_user', ['token', 'userinfo']),
			...mapState('m_cart', ['cart']),
			isFullCheck() {
				return this.total == this.checkedCount
			}
		},
		name: "my-settle",
		data() {
			return {

			};
		},
		methods: {

			...mapMutations('m_cart', ['updateAllGoodsState']),

			fullCheckHandle() {
				// 修改购物车中所有商品的选中状态
				// !this.isFullCheck 表示：当前全选按钮的状态取反之后，就是最新的勾选状态
				this.updateAllGoodsState(!this.isFullCheck)
			},
			// 点击了结算按钮
			settlement() {
				// 1. 先判断是否勾选了要结算的商品
				if (!this.checkedCount) return uni.$showMsg('请选择要结算的商品！')

				// 2. 再判断用户是否选择了收货地址
				if (!this.addstr) return uni.$showMsg('请选择收货地址！')
				if (this.userinfo.avatarUrl === undefined) {
					// console.log(this.userinfo.avatarUrl)
					// console.log("头像为空 没登录")
					uni.$showMsg('请先登录')

					setTimeout(function() {
						uni.$showMsg('再在前往登录页面')
					}, 1000);

					setTimeout(function() {
						uni.switchTab({
							url: '/pages/my/my'
						})
					}, 1500);

				} else {
					// console.log(this.userinfo.avatarUrl)
					// console.log("头像不为为空 已经登录")
					uni.$showMsg('功能开发中')
					
				}
				//

			},
		}
	}
</script>

<style lang="scss">
	.my-settle-container {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		height: 50px;
		// 将背景色从 cyan 改为 white
		background-color: white;
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding-left: 5px;
		font-size: 14px;

		.radio {
			display: flex;
			align-items: center;
		}

		.amount {
			color: #c00000;
			font-size: 16px;
			font-weight: bold;
		}

		.btn-settle {
			height: 36px;
			min-width: 70px;
			background-color: #c00000;
			color: white;
			line-height: 36px;
			text-align: center;
			padding: 0 10px;
			border-radius: 18px;
			margin-right: 10px;
		}
	}
</style>
